<?php
/**
 * @filesource /modules/user/Form/Login.php
 * @abstract Generate a Login form, where no lable is set
 *     see /modules/user/views/register/register.phtml for how the form is generated.
 */
class user_Form_NewRole extends Zend_Form
{

    protected $_noDecorator = array(
        'ViewHelper', 
        'Errors'
    );
    
    public function init()
    {
        $role = new user_Model_Role(); //for DbUnique validators

                // set the method for the display form to POST
        $this->setMethod('post');
		$this->setAction('/en/user/role/new'); //TODO
		
        
		//common filters & validators for all fields
        $filterTrim = new Zend_Filter_StringTrim();
        $validatorNotEmpty = new Zend_Validate_NotEmpty();
        $validatorNotEmpty->setMessage(__('This field is required, you cannot leave it empty'));


        // rolename
        $rolename = new Zend_Form_Element_Text('rname', array('disableLoadDefaultDecorators' => true,
                                                                 'class' => 'inputText',
                                                                 'required' => true));
        //$validatorAlnum = new Zend_Validate_Regex('/([a-zA-Z0-9\.])*/');
        //$validatorAlnum->setMessage(__('You can use only latin letters and numbers'));
        $validatorStringLength = new Zend_Validate_StringLength(3, 32);
        $validatorStringLength->setMessages(array(
            Zend_Validate_StringLength::TOO_SHORT => __('Your rolename have to be between 3 and 32 symbols long'),
            Zend_Validate_StringLength::TOO_LONG => __('Your rolename have to be between 3 and 32 symbols long'),
            )
        );
        $validatorUniqueRolename = new Clu_Validate_DbUnique($role, 'rname');
        $validatorUniqueRolename->setMessage(__('This rolename already exists'));
             
        $rolename->addValidator($validatorNotEmpty, true)
                 ->addFilter($filterTrim)
                 ->addValidator($validatorStringLength)
                 ->addValidator($validatorUniqueRolename)
                 ->addDecorators($this->_noDecorator);
                 
        $this->addElement($rolename);
            
        //submit
        // add the submit button
        $submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true, 
                                                               'label' => __('Create') ));
        $submit->addDecorators($this->_noDecorator);
        $this->addElement($submit);

    }
    
}